package org.balisunrise.test;

/*
 *  Copyright (C) 2010 Glauco
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */



import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import javax.persistence.*;
import org.balisunrise.annotation.VisualEntity;
import org.balisunrise.annotation.ColumnDefinition;
import org.balisunrise.annotation.CriteriaDefinition;
import org.balisunrise.annotation.Editor;
import org.balisunrise.annotation.FieldDefinition;
import org.balisunrise.annotation.Filter;
import org.balisunrise.annotation.FilterCriteria;
import org.balisunrise.annotation.FilterType;
import org.balisunrise.annotation.Grid;
import org.balisunrise.annotation.GridColumn;
import org.balisunrise.annotation.Panel;
import org.balisunrise.annotation.PanelField;
import org.balisunrise.annotation.Search;
import org.balisunrise.annotation.Transaction;

/**
 *
 * @author Glauco
 */
@Entity
@VisualEntity(
    panels=@Panel(alias={"default"},title="Simple Entity"),
    filters=@Filter(alias={"default"}),
    grids=@Grid(alias={"default"}),
    searchs=@Search(alias="default",filter="default",grid="default",title="Search Simple Entity"),
    editors=@Editor(alias="default",panel="default",title="Simple Entity Editor"),
    transactions=@Transaction(alias="default",editor="default",search="default",title="Simple Entity Transaction")
)
public class SimpleEntity implements Serializable{

    @Transient
    private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        propertyChangeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        propertyChangeSupport.removePropertyChangeListener(listener);
    }
    
    public static final String PROP_ID = "id";
    public static final String PROP_DESCRIPTION = "description";
    public static final String PROP_ALIAS = "alias";

    @Id
    @SequenceGenerator(name="hibernate_sequence")
    @GeneratedValue()
    private Long id;

    @Column(length=40)
    @PanelField(
        definitions=@FieldDefinition(alias={"default"},label="Description",index=1)
    )
    @FilterCriteria(
        definitions=@CriteriaDefinition(alias={"default"},label="Description",filterType=FilterType.ILIKE)
    )
    @GridColumn(
        definitions=@ColumnDefinition(alias={"default"},name="Description",width=240,index=1)
    )
    private String description;

    @Column(name="aliass",length=15)
    @PanelField(
        definitions=@FieldDefinition(alias={"default"},label="Alias",index=0)
    )
    @GridColumn(
        definitions=@ColumnDefinition(alias={"default"},name="Alias",width=240,index=0)
    )
    private String alias;


    public String getAlias() {
        return alias;
    }

    public void setAlias(String alias) {
        String oldAlias = this.alias;
        this.alias = alias;
        propertyChangeSupport.firePropertyChange(PROP_ALIAS, oldAlias, alias);
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        String oldDescription = this.description;
        this.description = description;
        propertyChangeSupport.firePropertyChange(PROP_DESCRIPTION, oldDescription, description);
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        Long oldId = this.id;
        this.id = id;
        propertyChangeSupport.firePropertyChange(PROP_ID, oldId, id);
    }

    @Override
    public String toString() {
        return "SimpleEntity{" + "alias=" + alias + " description=" + description + '}';
    }


}
